
package com.kedacom.ctsp.authority.dao;

import com.kedacom.ctsp.authority.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 用户 DAO接口
 *
 * @author sunchenjie
 */
public interface UserJpaDao extends JpaRepository<User, String> {

    /**
     * 根据personId，获取userId
     *
     * @param personIds
     * @return
     */
    @Query(nativeQuery = true, value = "select DISTINCT id from user where person_id in ?1")
    List getUserIdsByPersonIds(List<String> personIds);

    /**
     * 根据userId获取userId和roleId
     *
     * @param userIds
     * @return
     */
    @Query(nativeQuery = true, value = "select user_id,role_id from user_role where (status =?2 or status is null) and user_id in ?1")
    List getUserRoleIds(List<String> userIds, int status);


    /**
     * 根据userId获取部门id
     *
     * @param userIds
     * @return
     */
    @Query(nativeQuery = true, value = "SELECT u.id as userId,d.id as deptId from user u,person p,department d where  u.id in ?1 and u.person_id = p.id and p.department_id = d.id")
    List getUserDeptIds(List<String> userIds);
}
